<?php

namespace app\admin\controller;

use app\admin\logic\DashboardLogic;
use app\basic\BaseController;
use hg\apidoc\annotation as Apidoc;
use support\Request;

/**
 * @Apidoc\Title("仪表盘接口")
 */
class DashboardController extends BaseController
{
    protected $logic;

    public function __construct()
    {
        $this->logic = new DashboardLogic();
        parent::__construct();
    }

     /**
     * @Apidoc\Title("获取仪表盘统计数据")
     * @Apidoc\Method("POST")
     * @Apidoc\Returned("data", type="object", desc="统计数据", children={
     *     @Apidoc\Returned("total_members", type="int", desc="平台会员总量"),
     *     @Apidoc\Returned("total_documents", type="int", desc="平台文档总数"),
     *     @Apidoc\Returned("today_orders", type="int", desc="今日订单数量"),
     *     @Apidoc\Returned("total_income", type="string", desc="累计收入金额"),
     *     @Apidoc\Returned("member_rate", type="string", desc="会员环比增长率"),
     *     @Apidoc\Returned("document_rate", type="string", desc="文档环比增长率"),
     *     @Apidoc\Returned("order_rate", type="string", desc="订单环比增长率"),
     *     @Apidoc\Returned("income_rate", type="string", desc="收入环比增长率")
     * })
     */
    public function statistics()
    {
        $data = $this->logic->getDashboardStatistics();
        return $this->success($data);
    }

    /**
     * @Apidoc\Title("获取财务统计数据")
     * @Apidoc\Method("POST")
     * @Apidoc\Returned("data", type="object", desc="统计数据", children={
     *     @Apidoc\Returned("total_recharge", type="string", desc="累计充值金额"),
     *     @Apidoc\Returned("total_withdraw", type="string", desc="累计提现金额"),
     *     @Apidoc\Returned("balance_amount", type="string", desc="用户剩余充值金额"),
     *     @Apidoc\Returned("pending_withdraw", type="string", desc="用户待提现金额"),
     * })
     */
    public function financeStatistics()
    {
        $data = $this->logic->getFinanceStatistics();
        return $this->success($data);
    }

    /**
     * @Apidoc\Title("获取待审核提现统计")
     * @Apidoc\Method("POST")
     * @Apidoc\Returned("data", type="object", desc="统计数据", children={
     *     @Apidoc\Returned("pending_count", type="int", desc="待审核提���笔数"),
     * })
     */
    public function withdrawPendingStats()
    {
        $data = $this->logic->getWithdrawPendingStats();
        return $this->success($data);
    }

    /**
     * @Apidoc\Title("获取消费统计数据")
     * @Apidoc\Method("POST")
     * @Apidoc\Param("type", type="string", require=true, desc="统计类型:week=本周,month=本月,year=本年")
     * @Apidoc\Returned("data", type="object", desc="统计数据", children={
     *     @Apidoc\Returned("dates", type="array", desc="日期列表"),
     *     @Apidoc\Returned("recharge", type="array", desc="充值金额列表"),
     *     @Apidoc\Returned("consume", type="array", desc="消费金额列表")
     * })
     */
    public function consumeStatistics(Request $request)
    {
        $type = $request->post('type', 'week');
        $data = $this->logic->getConsumeStatistics($type);
        return $this->success($data);
    }

}